// PHSShareTest.cpp: implementation of the PHSShareTest class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PHSShareTest.h"
#include "FunctionRegister.h"
#include "FunctionObject.h"
#include "part.h"
//#include "PartPropertyDB.h"
#include "..\Command\JointCommand.h"
#include "AutoJointGenerator.h"
#include "joint.h"
#include "joinInfo.h"
#include "SupportHanger.h"
#include "PersistentFacade.h"
#include "SHCaculateCommand.h"
#include "PHSApp.h"
#include "PartCrudeDataSet.h"
#include "SupportHangerManager.H"
#include "DlgNewProject.h"
#include "ProjectGenerator.h"
#include "ProjectManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPPUNIT_TEST_SUITE_REGISTRATION( PHSShareTest );

PHSShareTest::PHSShareTest()
{

}

PHSShareTest::~PHSShareTest()
{

}

void PHSShareTest::Test_Create()
{
	FunctionRegisterInfo* pInfo = NULL;
	CPPUNIT_ASSERT(GetFunctionRegister().FindInfo(1, pInfo));

	FunctionObject* pObject = pInfo->CreateObject();
	CPPUNIT_ASSERT(pObject != NULL);
	delete pObject;
}

void PHSShareTest::Test_Fun()
{/*
	FunctionRegisterInfo* pInfo = NULL;
	CPPUNIT_ASSERT(GetFunctionRegister().FindInfo(1, pInfo));

	FunctionObject* pObject = pInfo->CreateObject();
	CPPUNIT_ASSERT(pObject != NULL);

	Part part;
	part.AttachFunction(pObject);
	FunctionObject* pFunction = part.GetFunction(1);
	CPPUNIT_ASSERT(pFunction != NULL);
	pFunction->Execute();

	delete pObject;*/
}

void PHSShareTest::Test_Property()
{
	Part part(_T("D1"));
//	CPPUNIT_ASSERT(FALSE);
}

void PHSShareTest::Test_Function()
{
	Part part(_T("L2"));
	Part part1(_T("D1"));
	Part part2(_T("D2"));
}

#include "PartConstructCommand.h"
void PHSShareTest::Test_Joint()
{
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2")));
	CPPUNIT_ASSERT(pL2);

	PartConstructCommand command(_T("L2.20"), pL2);
	CPPUNIT_ASSERT(command.Execute());

	Part* pL8 = GetPartGenerator().Generate(_T("L8"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L8")));
	CPPUNIT_ASSERT(pL8);

	JointCommand jointcommand(pL2, pL8);
	CPPUNIT_ASSERT(jointcommand.Execute());

	delete pL2;
	delete pL8;
}


void PHSShareTest::Test_Get_Data()
{
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2")));

	PartConstructCommand command(_T("L2.20"), pL2);
	CPPUNIT_ASSERT(command.Execute());

	delete pL2;
} 

void PHSShareTest::Test_Get_AnyPartData()
{
	Part* pD1 = GetPartGenerator().Generate(_T("D1"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("D1")));
	Part* pL3 = GetPartGenerator().Generate(_T("L3"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L3")));
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2")));
	Part* pL8 = GetPartGenerator().Generate(_T("L8"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L8")));
	CPPUNIT_ASSERT(pD1);
	CPPUNIT_ASSERT(pL3);
	CPPUNIT_ASSERT(pL2);
	CPPUNIT_ASSERT(pL8);

	PartConstructCommand command(_T("D1.558H"), pD1);
	CPPUNIT_ASSERT(command.Execute());

	JointCommand jointcommand_1(pD1, pL3);
	CPPUNIT_ASSERT(jointcommand_1.Execute());
	JointCommand jointcommand_2(pL3, pL8);
	CPPUNIT_ASSERT(jointcommand_2.Execute());
	JointCommand jointcommand_3(pL8, pL2);
	CPPUNIT_ASSERT(jointcommand_3.Execute());

	delete pD1;
	delete pL3;
	delete pL2;
	delete pL8;
}

#include "PipeJointPort.h"
void PHSShareTest::Test_Generate_Special_Joint_Regular()
{
	Part pipe;
	PipeJointPort* pPort = new PipeJointPort;
	CPPUNIT_ASSERT(pPort);
	pPort->JointStyle(JointFunction::ePIPE);
	pPort->Press(UeVector(0,0,-5000));
	pPort->PipeDiameter(450);
	pPort->Temperature(200);

	pipe.AttachFunction(pPort);

	Part* pD1 = GetPartGenerator().Generate(_T("D1"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("D1")));
	Part* pL3 = GetPartGenerator().Generate(_T("L3"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L3")));
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2")));
	Part* pL8 = GetPartGenerator().Generate(_T("L8"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L8")));
	CPPUNIT_ASSERT(pD1);
	
	JointCommand jointcommand(&pipe, pD1);
	CPPUNIT_ASSERT(jointcommand.Execute());
	JointCommand jointcommand_1(pD1, pL3);
	CPPUNIT_ASSERT(jointcommand_1.Execute());
	JointCommand jointcommand_2(pL3, pL8);
	CPPUNIT_ASSERT(jointcommand_2.Execute());
	JointCommand jointcommand_3(pL8, pL2);
	CPPUNIT_ASSERT(jointcommand_3.Execute());

	delete pD1;
	delete pL3;
	delete pL2;
	delete pL8;
//	PipeJointPort pPort = new 
}

#include "ForceAssignCommand.h"

void PHSShareTest::Test_Force_Assign()
{
	Part* pD1 = GetPartGenerator().Generate(_T("D1"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("D1")));
	CPPUNIT_ASSERT(pD1);

	PartConstructCommand command(_T("D1.558H"), pD1);
	CPPUNIT_ASSERT(command.Execute());

	ForceAssignCommand ForceAssign(JointInfo(pD1).GetFirst());
	for(int i = 0; i < 5; i++)
	{
		CPPUNIT_ASSERT(ForceAssign.Execute());
	}

	delete pD1;
}

void PHSShareTest::Test_Choose_Spring()
{
/*	SupportHanger sh;
	sh.SetVolumeID(GetPHSApp()->GetCurProjectVolumeID());
	sh.SetZdjh(atol(GetPHSApp()->GetCurZdjh()));
	sh.ReadDataFromDB();
	sh.SetAssemblyLoad(13368);
	sh.SetWorkLoad(13368);
	sh.SetStructureLoad(13368);
	sh.SetHotDisplacementZ(-48);
	PartString* pString = sh.GetSupportStrings().GetAt(0);

	CString strStandard_T2 = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("T2"));
	CPPUNIT_ASSERT(!strStandard_T2.IsEmpty());

	Part* pT2 = GetPartGenerator().Generate(_T("T2"), strStandard_T2);
	CPPUNIT_ASSERT(pT2);

	pString->AddPart(pT2);

	CString strStandard_T21 = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("T2"));
	CPPUNIT_ASSERT(!strStandard_T21.IsEmpty());

	Part* pT21 = GetPartGenerator().Generate(_T("T2"), strStandard_T21);
	CPPUNIT_ASSERT(pT21);

	pString->AddPart(pT21);	

	CString strStandard_L2 = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2"));
	CPPUNIT_ASSERT(!strStandard_L2.IsEmpty());

	Part* pL2 = GetPartGenerator().Generate(_T("L2"), strStandard_L2);
	CPPUNIT_ASSERT(pL2);

	pString->AddPart(pL2);

	SHCaculateCommand command(&sh);
	CPPUNIT_ASSERT(command.Execute());*/
}

void PHSShareTest::Test_Choose_ConstSpring()
{
/*	SupportHanger sh;

	sh.SetVolumeID(GetPHSApp()->GetCurProjectVolumeID());
	sh.SetZdjh(atol(GetPHSApp()->GetCurZdjh()));
	sh.ReadDataFromDB();
	sh.SetAssemblyLoad(2900);
	sh.SetWorkLoad(2900);
	sh.SetStructureLoad(2900);
	sh.SetHotDisplacementZ(230);
	PartString* pString = sh.GetSupportStrings().GetAt(0);

	CString strStandard_58VA = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("58VA"));
	CPPUNIT_ASSERT(!strStandard_58VA.IsEmpty());
	Part* p58VA = GetPartGenerator().Generate(_T("58VA"), strStandard_58VA);
	CPPUNIT_ASSERT(p58VA);
	pString->AddPart(p58VA);

	SHCaculateCommand command(&sh);
	CPPUNIT_ASSERT(TRUE);
	CPPUNIT_ASSERT(!command.Execute());*/
}

void PHSShareTest::Test_InitProperty()
{
	Part* pD1 = GetPartGenerator().Generate(_T("D1"),
		GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("D1")));
	CPPUNIT_ASSERT(pD1);

	PartCrudeDataSet* pSet = GetPersistentFacade().GetPartCrudeDataSet();
	pSet->SetDataStandard(pD1->GetStandard());
	CPPUNIT_ASSERT(pSet->InstancePart(pD1, _T("D1.558H")));
	CPPUNIT_ASSERT(pSet->InitProperty(*pD1));
	pSet->Close();

	delete pD1;

}

void PHSShareTest::Test_ConstSpringPort()
{
	CString strStandard_58VA = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("58VA"));
	CPPUNIT_ASSERT(!strStandard_58VA.IsEmpty());
	Part* p58VA = GetPartGenerator().Generate(_T("58VA"), strStandard_58VA);
	CPPUNIT_ASSERT(p58VA);

	CString strStandard_L2 = GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("L2"));
	CPPUNIT_ASSERT(!strStandard_L2.IsEmpty());

	Part* pL2 = GetPartGenerator().Generate(_T("L2"), strStandard_L2);
	CPPUNIT_ASSERT(pL2);

	PartConstructCommand command(_T("L2.20"), pL2);
	CPPUNIT_ASSERT(command.Execute());

	JointCommand jointcommand(pL2, p58VA);
	CPPUNIT_ASSERT(!jointcommand.Execute());
//	ConstSpringJointPort* pPort = new ConstSpringJointPort;
//	pPort->SetForce(UeVector(0,0,10000));
//	p58VA->AttachFunction(pPort);

//	pPort->jointPort();

	delete p58VA;
	delete pL2;
}

void PHSShareTest::Test_Choose_Part()
{
	GetPartGenerator().Generate();
}

void PHSShareTest::Test_Generate_SupportHanger()
{
	SupportHangerManager SHManager;

	SupportHanger* pSH = SHManager.GetSupportHanger(_T("1"));
	CPPUNIT_ASSERT(pSH);
}

void PHSShareTest::Test_New_Project_Dlg()
{
	Project* pPrj = GetProjectGenerator().Generate();
	delete pPrj;
}

void PHSShareTest::Test_Open_Project_Dlg()
{
	Project* pPrj = GetProjectManager().OpenProject();
}
#include "PropertyCustomVisitor.h"
#include "PropertyWindow.h"

void PHSShareTest::Test_Property_Window()
{
	Part* pD1 = GetPartGenerator().Generate(_T("D1"), GetPersistentFacade().GetCurPartSet()->GetCurStandardOfPart(_T("D1")));
	CPPUNIT_ASSERT(pD1);

	PropertyCustomVisitor visitor;

	PropertyStack::Iterator* pIt = pD1->GetPropertyStack()->NewIterator();
	for(pIt->Begin(); !pIt->End(); pIt->Next())
	{
		PropertyVariable* pVar = static_cast<PropertyVariable*>(pIt->Get());
		ASSERT(pVar);

		pVar->Accept(visitor);
	}
	delete pIt;

	CFrameWnd* pFrame = (CFrameWnd*)RUNTIME_CLASS(CFrameWnd)->CreateObject();
	pFrame->Create(NULL, _T("dsf"));
	pFrame->ShowWindow(SW_SHOW);

	PropertyWindow* pWnd = (PropertyWindow*)RUNTIME_CLASS(PropertyWindow)->CreateObject();
	pWnd->SetPropertyVisitor(&visitor);
	static_cast<CWnd*>(pWnd)->Create(NULL, _T("d"), WS_CHILD|WS_VISIBLE|WS_BORDER, CRect(0,0,200,500), pFrame, 1);
}